'use strict';
module.exports = {
	/**
	 * 查询点赞列表
	 * @url client/user/kh/getPraiseList 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let { client, page, pageSize } = data;

		let dbName = "db-praise";

		res["data"] = await vk.baseDao.selects({
			dbName,
			getMain: true,
			pageIndex: page || 1,
			pageSize: pageSize || 1,
			whereJson: {
				uid: userInfo._id
			},
			foreignDB: [
				{
					dbName:"db-article",
					localKey:"article_id",
					foreignKey:"_id",
					as:"article",
					limit: 1,
					fieldJson: {
						wx_openid: false
					},
					foreignDB: [
						{
							dbName:"uni-id-users",
							localKey:"uid",
							foreignKey:"_id",
							as:"userInfo",
							limit: 1,
							fieldJson: {
								nickname: true,
								avatar: true
							}
						}
					]
				}
			],
			sort: [{name: "_add_time", type: "desc"}]
		})
		
		res["data"] = res["data"].map(item => item = item.article)
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
